#pragma one

#include <iostream>
#include <boost/asio.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "ansyc_echo_server.h"

#include <map>

class Session:public std::enable_shared_from_this<Session>
{
public:
    explicit Session(boost::asio::io_context &ioc,Server *server):socket_(ioc),server_(server){
            boost::uuids::uuid  a_uuid = boost::uuids::random_generator()();
            uuid_ = boost::uuids::to_string(a_uuid);
    };
    ~Session(){std::cout << "session destructor." << std::endl;};
    void Start();
    std::string GetUuid()const{return uuid_;};
    boost::asio::ip::tcp::socket& Socket(){return socket_;};
    //void ClearSelf(std::string uuid){server_->ClearSession(uuid);};
private:
    boost::asio::ip::tcp::socket socket_;

    Server *server_;
    enum{max_length = 1024};
    char data_[max_length];

    std::string uuid_;//配合map存储session

    void ReadHandle(const boost::system::error_code error,std::size_t bytes_transferred,
    std::shared_ptr<Session>self_shared_);
    void WriteHandle(const boost::system::error_code error,std::size_t bytes_transferred,
    std::shared_ptr<Session>self_shared_);
};

